angular.module('myApp').controller('q-city',['$css','$http','$scope',function($css,$http,$scope){
		$css.add('./city/city.css')
		$http.get('./data/h3.json').success(function(data){
//			console.log(data)
//			var arr=data.data;
			$scope.arr = data.data;
			  
		})
		$http.get('./data/city.json').success(function(datas){

			$scope.cityArr=datas.data;
		
		})		
	$(document).ready(function(){
		
		$('.q-shopCar').click(function(){
			var myData = JSON.parse(localStorage.getItem('qiu'));

			if(myData!=null){

				$('.q-shopCar').attr('href','/#/shopping');
			}else{
				
				$('.q-shopCar').attr('href','/#/login');
			}	
		})
		
		setTimeout(banner,100) 
		
      function banner(){
          var $ban=$('#q-ban');
          var $trun = $('#q-turn');
          var $imgs = $('.imgs');
      	  var $dians = $('#q-turn>.q-dot>span'); 
          var w = parseInt($trun.css('width'));
//        console.log($ban)
//        $ban.width(w*$imgs.length);

          var index = 0;

                 for(var j=0 ; j<$dians.length; j++){
      				$dians[j].style.background='#c8cece';	
      			}
     $dians[0].style.background='green';
          function nextFn(){
      			index++;
            if(index > $imgs.length-1){
              index=0;
            }
            for(var j=0 ; j<$dians.length; j++){
      				$dians[j].style.background='#c8cece';	
      			}
      			$dians[index].style.background='green';
          var left1 = index*w *- 1;
          $ban.css('left',left1)
           }
          function clearTimer(){
            clearInterval(timer);
            timer = setInterval(nextFn , 2000);
          }
          var timer = setInterval(nextFn , 2000);
          var ban=document.querySelector('#q-ban')
          	ban.addEventListener('touchstart', function (e) {
                var touch = e.targetTouches[0];
                startX = touch.pageX;
            });
            ban.addEventListener('touchmove', function (e) {
                var touch = e.targetTouches[0];
                endX = touch.pageX;
                clearInterval(timer);
            })
            ban.addEventListener('touchend', function (e) {
                if (endX - startX > 100) {
                	index--;           			
						if(index<0){
							index = $imgs.length-1;
						}							
						for(var j=0 ; j<$dians.length; j++){
      						$dians[j].style.background='#c8cece';      				
      					}
      					$dians[index].style.background='green';						
						var left = index*w*-1;
						$ban.css('left',left);
						clearTimer();                                 
                } else if (endX - startX < -100) {
                		nextFn();
						clearTimer();                       
                }
                   clearTimer(); 
            })
        }	
})
}])

